package com.wasion.gydpe.common.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;

public class LogAspect {

	public void doAfter(JoinPoint jp) {
		Object[] args = jp.getArgs();
		for (int i = 0; i < args.length; i++) {
			System.out.println(args[i]); // 输出传入的参数
		}
		System.out.println(jp.getSignature().getName()); // 调用的方法名
		System.out.println("---------权限检测--------------");
		System.out.println("log Ending method: "
				+ jp.getTarget().getClass().getName() + "."
				+ jp.getSignature().getName());
	}

	public Object doAround(ProceedingJoinPoint pjp) throws Throwable {
		long time = System.currentTimeMillis();
		Object retVal = pjp.proceed();
		time = System.currentTimeMillis() - time;
		System.out.println("process time: " + time + " ms");
		return retVal;
	}

	public void doBefore(JoinPoint jp) {
		System.out.println("log Begining method: "
				+ jp.getTarget().getClass().getName() + "."
				+ jp.getSignature().getName());
	}

	public void doThrowing(JoinPoint jp, Throwable ex) {
		System.out.println("method " + jp.getTarget().getClass().getName()
				+ "." + jp.getSignature().getName() + " throw exception");
		System.out.println(ex.getMessage());
	}

	public void sendEx(String ex) {
		// 发送短信或邮件提醒
		System.out.println("邮件发送成功...");
	}
}
